package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Party;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.serverpackets.S_PacketBoxGm;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1PartyRecall implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1PartyRecall.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1PartyRecall();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      L1PcInstance target = World.get().getPlayer(arg);
      if (target != null) {
        L1Party party = target.getParty();
        if (party != null) {
          int x = pc.getX();
          int y = pc.getY() + 2;
          short map = pc.getMapId();
          ConcurrentHashMap<Integer, L1PcInstance> pcs = party.partyUsers();
          if (pcs.isEmpty())
            return; 
          if (pcs.size() <= 0)
            return; 
          Iterator<L1PcInstance> iterator = pcs.values().iterator();
          while (iterator.hasNext()) {
            L1PcInstance pc2 = iterator.next();
            try {
              L1Teleport.teleport(pc2, x, y, map, 5, true);
              pc2.sendPackets((ServerBasePacket)new S_SystemMessage("管理员召唤!"));
            } catch (Exception e) {
              _log.error("队伍召唤异常", e);
            } 
          } 
        } else {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(String.valueOf(arg)) + " 不是一个队伍成员!"));
        } 
      } else {
        int mode = 3;
        pc.sendPackets((ServerBasePacket)new S_PacketBoxGm(pc, 3));
      } 
    } catch (Exception e2) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
